#pragma once

#include <string>
#include <functional>

class TimerTask
{
public:
    using TaskFunc = std::function<void()>;
    using ReleaseFunc = std::function<void()>;

    TimerTask(std::string name, uint32_t timeout, const TaskFunc &cb);
    ~TimerTask();

    //取消定时任务
    void cancel() { canceled_ = true; }
    //设置定时器任务的释放函数
    void setRelease(const ReleaseFunc &cb) { release_ = cb; }
    uint32_t delayTime() { return timeout_; }

private:
    std::string name_; // TimerTask对象的名称
    uint32_t timeout_; // 定时任务的超时时间
    bool canceled_;             //标识任务是否被取消
    TaskFunc taskCallback_;    //定时任务
    ReleaseFunc release_;       // 用于删除TimerWheel中保存的定时器对象信息
};